'use strict';
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const f = require('../doc/Document.cjs'),
  p = require('./compose-node.cjs'),
  v = require('./resolve-end.cjs'),
  N = require('./resolve-props.cjs');
function b(a, l, { offset: i, start: r, value: t, end: s }, c) {
  const u = Object.assign({ _directives: l }, a),
    e = new f.Document(void 0, u),
    m = {
      atRoot: !0,
      directives: e.directives,
      options: e.options,
      schema: e.schema,
    },
    o = N.resolveProps(r, {
      indicator: 'doc-start',
      next: t ?? (s == null ? void 0 : s[0]),
      offset: i,
      onError: c,
      startOnNewline: !0,
    });
  o.found &&
    ((e.directives.docStart = !0),
    t &&
      (t.type === 'block-map' || t.type === 'block-seq') &&
      !o.hasNewline &&
      c(
        o.end,
        'MISSING_CHAR',
        'Block collection cannot start on same line with directives-end marker',
      )),
    (e.contents = t
      ? p.composeNode(m, t, o, c)
      : p.composeEmptyNode(m, o.end, r, null, o, c));
  const d = e.contents.range[2],
    n = v.resolveEnd(s, d, !1, c);
  return n.comment && (e.comment = n.comment), (e.range = [i, d, n.offset]), e;
}
exports.composeDoc = b;
